#@layout()

#define main()
<div class="jfa-header-box" id="jfa-header-box">
    <div class="jfa-crumbs" id="jfa-crumbs">
        物料信息维护
    </div>
    #include("/_view/common/_header_right.html")
</div>
<div class="jfa-content-box" id="jfa-content-box">
    <div class="jfa-content" id="jfa-content">
        <div class="margin-top-30">
            <form class="form-horizontal actionPanel" action="#" method="get">
                <div class="row">
                    <div class="form-group col-lg-4">
                        <label class="col-lg-4 control-label">物料编码</label>
                        <div class="col-lg-8">
                            <input type="text" id="form-materialCode" class="form-control" name="materialCode">
                        </div>
                    </div>
                    <div class="form-group col-lg-5">
                        <label class="col-lg-4 control-label">物料名称</label>
                        <div class="col-lg-8">
                            <input type="text" id="form-remark" class="form-control" name="remark">
                        </div>
                    </div>
                    <div class="form-group col-lg-2">
                        <div class="col-lg-12">
                            <button type="button" class="btn btn-primary" onclick="search()">查询</button>
                            <button type="reset" class="btn btn-default">重置</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>

        <div id="toolbar">
            <a class="btn btn-primary btn-sm margin-right-10" href="#(ctx)/admin/material/add" >
                <i class="fa fa-plus"></i>
                添加
            </a>
        </div>
        <table id="material">

        </table>
    </div>
</div>

<script type="text/javascript">
 	var datagridHeight=$("#jfa-content").height()-80;
 	$('#material').bootstrapTable({
        url: '#(ctx)/admin/material/list',
        method: 'get',
        striped: true,
        cache: false,
        pagination: true,
        sortable: false,
        sortOrder: "asc",
        toolbar:"#toolbar",
        toolbarAlign:"right",
        queryParams: function (params) {
	            var data = {
	                    pageSize: params.limit,
	                    offset: params.offset,
	                    'materialCode': $("#form-materialCode").val(),
	                    'remark': $("#form-remark").val(),
	            };
	            return data;
        },
        sidePagination: "server",
        pageNumber:1,
        pageSize:10,
        pageList: [10,20,30,40,50,100],
        search: false,
        strictSearch: true,
        showColumns: false,
        showRefresh: false,
        minimumCountColumns: 2,
        clickToSelect: true,
       	height: datagridHeight,
        uniqueId: "id",
        showToggle:false,
        cardView: false,
        detailView: false,
        columns: [
            {
                field: 'materialCode',  title: '物料编码'
            }, {
                field: 'remark',  title: '物料名称'
            }, {
                 field: 'createAt',  title: '创建时间'
            }, {
            	field: 'createUser',  title: '创建人'
            },{
                field: 'updateAt',  title: '修改时间'
            }, {
            	field: 'changeUser',  title: '修改人'
            },{
                title: '操作',formatter:operaterFormatter
            }
        ]
    });


function operaterFormatter(value, row, index){
	return "<a href='#(ctx)/admin/material/edit?id="+row.id+"'>"+
	"<i class='fa fa-pencil' title='修改'></i>"+
	" </a> &nbsp"+
	 "<a href='#' onclick='deleteById("+row.id+")'>"+
	"<i class='fa fa-trash' title='删除'></i>"+
	" </a>"
}

function search(){
	$('#material').bootstrapTable("refresh",{silent: true});
    layer.msg('操作成功');
}

function deleteById(id){
    layer.confirm("确认删除该物料信息？", {
		icon: 0
		, title:''
		, shade: 0.4
		, offset: "139px"
	}, function(index) {
		$.ajax({
			url:"#(ctx)/admin/material/delete",
			data:{"id":id},
			dataType:"json",
			success:function(ret){
				$('#material').bootstrapTable("refresh");
			    layer.msg(ret.msg);
			    layer.close(index);
			},
			error:function(){
				layer.close(index);
			}
		});

	});
}
</script>
#end
